package com.CampusForum.community.controller;

import com.CampusForum.community.entity.Comment;
import com.CampusForum.community.service.CommentService;
import com.CampusForum.community.util.HostHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;


@Controller
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private HostHolder hostHolder;
    @Autowired
    private CommentService commentService;

    @PostMapping("/add/{discussPostId}")
    public String insertComment(@PathVariable("discussPostId") int discussPostId,
                           Comment comment) {
        comment.setStatus(0);
        comment.setCreateTime(new Date());
        comment.setUserId(hostHolder.getUser().getId());
        commentService.insertComment(comment);

        return "redirect:/discuss/detail/" + discussPostId;
    }
}
